#include "timer.h"

// 硬件定时中断---定时时间ms
void TIM_Init(Timer Timer,uint16_t Scheduled_Time)
{
    hw_timer_t *hw_tim;

    hw_tim = timerBegin(Timer, 80, true);

    timerAlarmWrite(hw_tim,Scheduled_Time * 1e3 ,true);

    // 四个定时器的中断函数注册
    if(Timer == Timer0)
    {
        timerAttachInterrupt(hw_tim,TIM_Interrupt_0,true);
    }

    if(Timer == Timer1)
    {
        timerAttachInterrupt(hw_tim,TIM_Interrupt_1,true);
    }

    if(Timer == Timer2)
    {
        timerAttachInterrupt(hw_tim,TIM_Interrupt_2,true);
    }

    if(Timer == Timer3)
    {
        timerAttachInterrupt(hw_tim,TIM_Interrupt_3,true);
    }

    // 使能定时器
    timerAlarmEnable(hw_tim);
}

// 定义四个定时中断函数，根据选用的定时器调用中断函数
__weak_symbol void TIM_Interrupt_0(void) {}
__weak_symbol void TIM_Interrupt_1(void) {}
__weak_symbol void TIM_Interrupt_2(void) {}
__weak_symbol void TIM_Interrupt_3(void) {}
